package com.ai.databao.web.system.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

import org.apache.commons.lang.StringUtils;

import com.ai.databao.web.system.util.XssUtil;

public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper{

	public XssHttpServletRequestWrapper(HttpServletRequest request) {
		super(request);
	}

	@Override
	public String getParameter(String name) {
		String value = super.getParameter(name);
		if(StringUtils.isBlank(value)){
			return value;
		}
		
		return XssUtil.htmlEncode(XssUtil.checkParam(value));
	}
	
	@Override
	public String[] getParameterValues(String name) {
		String[] values = super.getParameterValues(name);
        if (values==null)  {
            return null;
        }
        int count = values.length;
        String[] encodedValues = new String[count];
        for (int i = 0; i < count; i++) {
            encodedValues[i] = XssUtil.htmlEncode(XssUtil.checkParam(values[i]));
        }
        return encodedValues;
	}
	
	@Override
	public String getHeader(String name) {
		String value = super.getHeader(name);
		if(StringUtils.isBlank(value)){
			return value;
		}
		return XssUtil.htmlEncode(XssUtil.checkParam(value));
	}
}
